/**
 * by ward @ harrydeep@163.com 
 * 2018
 */
package top.wardyan.base.action;

import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.wb.swt.SWTResourceManager;

import top.wardyan.base.config.Const;

/**
 * 所有新增,修改窗口的基类之一:非全屏的,800*600的
 * @author ward
 * 用途:
 * 版本:
 * 创建:
 * 更新:
 */
public abstract class BaseBillShell<T extends BaseBillShell<T>> extends Shell {

	protected T self;
	protected Label lblTitle;
	protected Integer type;	// 类型: 1 600*480; 2 800*600
	
	
	@Override
	public void open(){
		super.open();
		this.layout();
	}
	
	public void go(){
		while (!this.isDisposed()) {
			if (!this.getDisplay().readAndDispatch()) {
				this.getDisplay().sleep();
			}
		}
	}

	
	public BaseBillShell() {
		//setSize(800, 600);
		this(2);
	}
	
	@SuppressWarnings("unchecked")
	public BaseBillShell(Integer type) {
		super(Const.display, SWT.CLOSE | SWT.APPLICATION_MODAL);
		this.type = type;
		this.self = (T) this;
		this.createContents();
	}

	
	private void createContents() {
		this.setBackground(Const.COLOR_WHITE);
		lblTitle = new Label(this, SWT.NONE);
		lblTitle.setBackground(SWTResourceManager.getColor(SWT.COLOR_WHITE));
		lblTitle.setAlignment(SWT.CENTER);
		lblTitle.setFont(Const.FONT_H5);
		
		lblTitle.setText(this.getTitle());
		
		this.setText(this.getTitle());
		if(this.type.equals(1))
			this.setSize(600, 480);
		else
			this.setSize(800, 600);
		this.setLocation((Const.SCREENWIDTH - this.getSize().x) / 2, (Const.SCREENHEIGHT - this.getSize().y) / 2);
		lblTitle.setBounds(0, 0, this.getSize().x, 40);
		this.open();
	}
	
	protected abstract String getTitle();

	@Override
	protected void checkSubclass() {
		// Disable the check that prevents subclassing of SWT components
	}
}
